package xixirupan.tmgp.tencent.com.vmeim.login.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.PopupWindow;

import xixirupan.tmgp.tencent.com.vmeim.R;
import xixirupan.tmgp.tencent.com.vmeim.login.presenter.IPostData;
import xixirupan.tmgp.tencent.com.vmeim.login.presenter.PopwindowPresenter;

/**
 * Created by lenovo on 2016/10/21.
 */

public class SelectPoupWindow extends PopupWindow {

    private Activity context;
   View mMenuView;
 //   Button btn_cancel;
  ListView listView;
    LayoutInflater inflater;

    //另外参数  View.OnClickListener itemsOnClick
   IPostData postData;
    public SelectPoupWindow(Activity context, final IPostData postData ) {

        super(context);
         this.postData =postData;

        this.context =context;

        //创建布局填充器
          inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //获取view布局
        mMenuView = inflater.inflate(R.layout.alert_dialog, null);
       listView= (ListView) mMenuView.findViewById(R.id.poup_distribute);
        PopwindowPresenter presenter =new PopwindowPresenter(listView,context,inflater);
        presenter.initListview(new IPostData() {
            @Override
            public void postTextData(String name, String ename) {
                postData.postTextData(name,ename);
            }
        });



//        btn_take_photo = (Button) mMenuView
//                .findViewById(R.id.btn_take_photo);
//        btn_pick_photo = (Button) mMenuView
//                .findViewById(R.id.btn_pick_photo);
//        btn_cancel = (Button) mMenuView
//               .findViewById(R.id.btn_cancel);
//        //取消按钮
//        btn_cancel.setOnClickListener(new View.OnClickListener() {
//
//            public void onClick(View v) {
//                //销毁弹出框
//                dismiss();
//            }
//        });
        //设置按钮监听
     //   btn_pick_photo.setOnClickListener(itemsOnClick);
     //   btn_take_photo.setOnClickListener(itemsOnClick);
        //设置SelectPicPopupWindow的View


        this.setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(WindowManager.LayoutParams.FILL_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
         this.setHeight(600);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
 //     this.setAnimationStyle(R.style.AnimBottom);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);

        //mMenuView添加OnTouchListener
        //监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mMenuView
                        .findViewById(R.id.pop_layout).getTop();
                int y=(int) event.getY();
                if(event.getAction()==MotionEvent.ACTION_UP){
                    if(y<height){
                        dismiss();
                    }
                }
                return true;
            }
        });

    }




}
